import vue from '@vitejs/plugin-vue'
import { defineConfig, loadEnv } from 'vite';
const path = require("path")
export default ({ mode }) => {
  return defineConfig({
    resolve: {
      alias: {
        '/@S': path.resolve(__dirname, './src/system/src'),
        '/@M': path.resolve(__dirname, './src/system/node_modules')
      }
    },
    plugins: [vue()],
    // 代理
    server: {
      port: 4000,
      // open: true
      proxy: {
        '/api': {
          target: loadEnv(mode, process.cwd()).VITE_APP_SERVER_URL,
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api/, '')
        },
        '/userfiles': {
          target: loadEnv(mode, process.cwd()).VITE_APP_SERVER_File,
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/userfiles/, 'userfiles')
        }
      }
    }
  })
}
